package com.telaxo.shooter2012.projectiles {
	import com.telaxo.shooter2012.Engine;
	import com.telaxo.shooter2012.gfx.Ship;
	import com.telaxo.shooter2012.interfaces.Projectile;

	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.events.Event;

	/**   
	 * @author Benjamin   
	 */
	public class LaserBlue extends MovieClip implements Projectile {
		// Récupération de l'image du laser
		[Embed(source="../gfx/swf/LaserBlue.swf")]
		private var Ressource : Class;
		private var stageRef : Stage;
		private var vitesseLaser : Number = 16;
		private var vx : Number;
		private var vy : Number;
		private var target : Ship;
		private var puissance : Number = 1;

		public function LaserBlue(s : Stage, x : Number, y : Number, t : Ship, pui : Number) {
			this.stageRef.addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
			stageRef = s;
			vx = 0;
			target = t;
			vy += vitesseLaser;
			// Ajout de l'image du laser
			var image : MovieClip = new Ressource();
			addChild(image);

			if (puissance == 2) {
				this.width += 5;
			}

			if (puissance == 3) {
				var leLaser : LaserBlue = new LaserBlue(stageRef, x + 15, y, t, 1);
				this.stageRef.addChildAt(leLaser, 2);
			}

			if (puissance == 4) {
				var leLaser2 : LaserBlue = new LaserBlue(stageRef, x + 15, y, t, 1);
				this.stageRef.addChildAt(leLaser2, 2);
				leLaser2.width += 5;
				this.width += 5;
			}

			if (puissance == 5) {
				var leLaser3 : LaserBlue = new LaserBlue(stageRef, x + 15, y, t, 1);
				var leLaser4 : LaserBlue = new LaserBlue(stageRef, x - 15, y, t, 1);
				this.stageRef.addChildAt(leLaser3, 2);
				this.stageRef.addChildAt(leLaser4, 2);
				this.x = x + vx * 2;
				this.y = y + vy * 2 - 10;
			} else {
				this.x = mouseX;
				this.y = mouseY;
				vy -= vitesseLaser;
			}
			// Ajout de l'image du laser
		
			/*
			if(puissance==6){
			var leLaser5 : LaserBlue = new LaserBlue(stageRef, target,x+15, y,1);
			var leLaser6 : LaserBlue = new LaserBlue(stageRef, target,x+15, y,1);
			this.stageRef.addChildAt(leLaser5, 2);
			this.stageRef.addChildAt(leLaser6, 2);
			leLaser5.width +=5;leLaser6.width +=5;
			this.width+=5;
			}
			
			if(puissance==7) {
			this.visible = false;
			var smokepuff2:LanceFlamme = new LanceFlamme(stageRef,x+15, y);
			this.stageRef.addChildAt(smokepuff2,2);
			target.delay = 0;
			// WHY WHY WHY !!!!!!
			// Ship_2.duree = 10;
			}
			
			if(puissance==8){
			target.fireTimer.delay = 100;	
			}
			
			if(puissance==9){
			this.width +=5;
			}
			
			if(puissance==10){
			var leLaser7 : LaserBlue = new LaserBlue(stageRef, target,x+15, y,1);
			this.stageRef.addChildAt(leLaser7, 2);
			}
			
			if(puissance==11){
			var leLaser8 : LaserBlue = new LaserBlue(stageRef, target,x+15, y,1);
			this.stageRef.addChildAt(leLaser8, 2);
			leLaser8.width +=5;
			this.width+=5;
			}
			
			if(puissance==12){
			var leLaser9 : LaserBlue = new LaserBlue(stageRef, target,x+15, y,1);
			var leLaser10 : LaserBlue = new LaserBlue(stageRef, target,x+15, y,1);
			this.stageRef.addChildAt(leLaser9, 2);
			this.stageRef.addChildAt(leLaser10, 2);

			}
			
			if(puissance==13){
			var leLaser11 : LaserBlue = new LaserBlue(stageRef, target,x+15, y,1);
			var leLaser12 : LaserBlue = new LaserBlue(stageRef, target,x+15, y,1);
			this.stageRef.addChildAt(leLaser11, 2);
			this.stageRef.addChildAt(leLaser12, 2);
			leLaser11.width +=5;leLaser12.width +=5;
			this.width+=5;
			}
			
			if(puissance==14){
			target.fireTimer.delay = 0;	
			}
			
			if(puissance==15){
			this.width +=50;
			}
			
			if(puissance==16){
			var leLaser7 : LaserBlue = new LaserBlue(stageRef, target,x+15, y,1);
			this.stageRef.addChildAt(leLaser7, 2);
			}
			
			if(puissance==17){
			var leLaser8 : LaserBlue = new LaserBlue(stageRef, target,x+15, y,1);
			this.stageRef.addChildAt(leLaser8, 2);
			leLaser8.width +=50;
			this.width+=50;
			}
			
			if(puissance==18){
			var leLaser9 : LaserBlue = new LaserBlue(stageRef, target,x+15, y,1);
			var leLaser10 : LaserBlue = new LaserBlue(stageRef, target,x+15, y,1);
			this.stageRef.addChildAt(leLaser9, 2);
			this.stageRef.addChildAt(leLaser10, 2);

			}
			
			if(puissance==19){
			var leLaser11 : LaserBlue = new LaserBlue(stageRef, target,x+15, y,1);
			var leLaser12 : LaserBlue = new LaserBlue(stageRef, target,x+15, y,1);
			this.stageRef.addChildAt(leLaser11, 2);
			this.stageRef.addChildAt(leLaser12, 2);
			leLaser11.width +=100;leLaser12.width +=100;
			this.width+=10;
			}
			
			if(puissance==7) {
			this.visible = false;
			var smokepuff2:LanceFlamme = new LanceFlamme(stageRef, x , y);
			this.stageRef.addChildAt(smokepuff2,2);
			target.fireTimer.delay = 0;
			// WHY WHY WHY !!!!!!
			// Ship_2.duree = 10;
			}
			
			if(puissance==8){
			target.fireTimer.delay = 100;	
			}
			
			if(puissance==9){
			this.width +=5;
			}
			
			if(puissance==10){
			var leLaser7 : LaserBlue = new LaserBlue(stageRef, x+15, y,t,1);
			this.stageRef.addChildAt(leLaser7, 2);
			}
			
			if(puissance==11){
			var leLaser8 : LaserBlue = new LaserBlue(stageRef, x+15, y,t,1);
			this.stageRef.addChildAt(leLaser8, 2);
			leLaser8.width +=5;
			this.width+=5;
			}
			
			if(puissance==12){
			var leLaser9 : LaserBlue = new LaserBlue(stageRef, x+15, y,t,1);
			var leLaser10 : LaserBlue = new LaserBlue(stageRef, x-15, y,t,1);
			this.stageRef.addChildAt(leLaser9, 2);
			this.stageRef.addChildAt(leLaser10, 2);

			}
			
			if(puissance==13){
			var leLaser11 : LaserBlue = new LaserBlue(stageRef, x+15, y,t,1);
			var leLaser12 : LaserBlue = new LaserBlue(stageRef, x-15, y,t,1);
			this.stageRef.addChildAt(leLaser11, 2);
			this.stageRef.addChildAt(leLaser12, 2);
			leLaser11.width +=5;leLaser12.width +=5;
			this.width+=5;
			}
			
			if(puissance==14){
			target.fireTimer.delay = 0;	
			}
			
			if(puissance==15){
			this.width +=50;
			}
			
			if(puissance==16){
			var leLaser13 : LaserBlue = new LaserBlue(stageRef, x+15, y,t,1);
			this.stageRef.addChildAt(leLaser13, 2);
			}
			
			if(puissance==17){
			var leLaser14 : LaserBlue = new LaserBlue(stageRef, x+15, y,t,1);
			this.stageRef.addChildAt(leLaser14, 2);
			leLaser8.width +=50;
			this.width+=50;
			}
			
			if(puissance==18){
			var leLaser15 : LaserBlue = new LaserBlue(stageRef, x+15, y,t,1);
			var leLaser16 : LaserBlue = new LaserBlue(stageRef, x-15, y,t,1);
			this.stageRef.addChildAt(leLaser16, 2);
			this.stageRef.addChildAt(leLaser15, 2);

			}
			
			if(puissance==19){
			var leLaser17 : LaserBlue = new LaserBlue(stageRef, x+15, y,t,1);
			var leLaser18 : LaserBlue = new LaserBlue(stageRef, x-15, y,t,1);
			this.stageRef.addChildAt(leLaser17, 2);
			this.stageRef.addChildAt(leLaser18, 2);
			leLaser11.width +=100;leLaser12.width +=100;
			this.width+=10;
			}
			}*/
		}

		public function supprimerProjectile() : void {
			removeEventListener(Event.ENTER_FRAME, loop);
			if (stageRef.contains(this)) stageRef.removeChild(this);
		}

		// Boucle du laser bleu
		private function loop(pEvt : Event) : void {
			y += vy;
			x += vx;

			// Si le laser est en dehors de l'écran
			if (x > 520 || y > 420 || x < -20 || y < -20) supprimerProjectile();

			for (var i : int = 0; i < Engine.listeEnnemis.length; i++) {
				if (hitTestObject(Engine.listeEnnemis[i].hit)) {
					Engine.listeEnnemis[i].estTouche();
					supprimerProjectile();
				}
			}
		}

		// Converti les degrés en radians
		public function degreesToRadians(degrees : Number) : Number {
			return degrees * Math.PI / 180;
		}
	}
}